/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.dongjiang.tax.system.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 东疆税务系统
 *
 * @author duanlikao
 * @created 2021/3/11
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum PersonalIncomeTaxEnum {

    PERSONAL_INCOME_TAX_TYPE_ONE(1,"不超过30,000元的部分", "0.05","0"),

    PERSONAL_INCOME_TAX_TYPE_TWO(2,"超过30,000 元至90,000元的部分", "0.10","1500"),

    PERSONAL_INCOME_TAX_TYPE_THREE(3,"超过 90,000 元至 300,000 元的部分", "0.20","10500"),

    PERSONAL_INCOME_TAX_TYPE_FOUR(4,"超过 300,000 元至 500,000 元的部分","0.30","40500"),

    PERSONAL_INCOME_TAX_TYPE_FIVE(5,"超过 500,000 元的部分", "0.35","65500"),

    ;

    private  Integer code;
    private  String msg;
    private  String sl;
    private  String sks;

    private static Map <Integer, PersonalIncomeTaxEnum> codeMap = Maps.newHashMap();

    public Integer getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public String getSl() {
        return this.sl;
    }

    public String getSks() {
        return this.sks;
    }

    public static String getSlBycode(Integer code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getSl() : StringUtils.EMPTY;
    }

    public static String getMsg(Integer code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(Integer code) {
        return codeMap.containsKey(code);
    }

    static {
        for (PersonalIncomeTaxEnum status : PersonalIncomeTaxEnum.values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static PersonalIncomeTaxEnum getPersonalIncomeTaxEnumByVal(Integer code) {
        return Arrays.stream(PersonalIncomeTaxEnum.values()).collect(Collectors.toMap(
                PersonalIncomeTaxEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }
}
